//
//  MainViewController.m
//  MRC_Playground
//
//  Created by Developer on 2021/9/30.
//

#import "MainViewController.h"
#import "TimerCrashVC.h"
#import "SafeTimerVC.h"
//#import "BlockViewController.h"
//#import "JK_EcpmModel.h"

@interface MainViewController ()

@end

@implementation MainViewController{
//    NSArray *_arr;
//    NSObject *_model;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    
//    [self demoArrayMinus];
    
//    NSArray *arr_self = [[NSArray alloc] initWithObjects:@"abc", nil];
//    NSArray *arr_auto = [NSArray arrayWithObject:@"abc"];
//    NSArray *arr_const = @[@"abc"];
    
//    NSArray *arr_self = [[NSArray alloc] init];
//    NSArray *arr_auto = [NSArray array];
//    NSArray *arr_const = @[];
    /*
     注意:非自己持有的情况有的时候是可以调用release方法而不崩溃的，因为NSString，NSArray，NSDictionary是类蔟的原因，加之不可变所以系统将其作为静态内容存在内存中
     所以内存管理方式不同于的NSObject，可以尝试NSArray *arr_auto = [NSArray array];然后调用[arr_auto release];不会产生崩溃
     */
    //此处NSLog模拟对arr_self和arr_auto的使用
//    NSLog(@"\n%@%p count:%lu - \n%@%p count: %lu - \n%@%p count:%lu",[arr_self class],arr_self,(unsigned long)[arr_self retainCount],[arr_auto class],arr_auto,(unsigned long)[arr_auto retainCount],[arr_const class],arr_const,(unsigned long)[arr_const retainCount]);
    //不再使用变量后需要对其进行释放，arr_self = nil是非必要的，是为了防止下文中还有使用arr_self造成崩溃
//    [arr_self release]; //arr_self = nil;
//    [arr_self release];
//    [arr_auto release]; arr_auto = nil;
//    [arr_auto release]; [arr_auto release];
    
    //假如在arr_self被释放后还有对arr_self的使用，因为arr_self已经是nil所以避免崩溃
//    NSLog(@"%@",arr_self);
    
    
    //2.autoRelease的使用,根据Apple文档的内容，需要延迟发送release的时候，特别是在方法中返回一个对象的时候会用到，我们用WorkerModel来演示
    
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    [super touchesBegan:touches withEvent:event];
//    BlockViewController *vc = [[BlockViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
//    [vc release]; vc = nil;
//}
//
//#pragma mark - Demos - 测试subarrayWithRange是否需要自己管理内存
//- (void)testArraySubarrayWithRange{
//    NSMutableArray *origArray = [[NSMutableArray alloc] initWithCapacity:0];
//    [origArray addObject:@"1"];
//    [origArray addObject:@"2"];
//    [origArray addObject:@"3"];
//    [origArray addObject:@"4"];
//
//    //subarrayWithRange不需要开发者自己管理内存
//    NSArray *arr = [origArray subarrayWithRange:NSMakeRange(0, 2)];
//    NSLog(@"%@",arr);
//
//    [origArray release]; origArray = nil;
//}
//
//#pragma mark - Demos - 数组取差集
//- (void)demoArrayMinus{
//    JK_EcpmModel *ecmp_9 = [[JK_EcpmModel alloc] init];
//    ecmp_9.ecpm = 9;
//    JK_EcpmModel *ecmp_8 = [[JK_EcpmModel alloc] init];
//    ecmp_8.ecpm = 8;
//    JK_EcpmModel *ecmp_7 = [[JK_EcpmModel alloc] init];
//    ecmp_7.ecpm = 7;
//    JK_EcpmModel *ecmp_6 = [[JK_EcpmModel alloc] init];
//    ecmp_6.ecpm = 6;
//    JK_EcpmModel *ecmp_4 = [[JK_EcpmModel alloc] init];
//    ecmp_4.ecpm = 4;
//    JK_EcpmModel *ecmp_2 = [[JK_EcpmModel alloc] init];
//    ecmp_2.ecpm = 2;
//
//    NSArray *flowArray = @[ecmp_9, ecmp_8, ecmp_7];
//    NSArray *successQueue = @[ecmp_8, ecmp_7, ecmp_6,ecmp_4, ecmp_2];
//    NSMutableSet *f_set = [NSMutableSet setWithArray:flowArray];
//    NSSet *s_set = [NSSet setWithArray:successQueue];
//    [f_set minusSet:s_set];
//    /**
//     sortDescriptorWithKey:属性名，NSString传入nil
//     ascending:YES升序
//     */
//    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"ecpm" ascending:NO];
//    NSArray *result = [f_set sortedArrayUsingDescriptors:@[sort]];
//    NSLog(@"%@",result);
//
//    [ecmp_9 release];
//    [ecmp_8 release];
//    [ecmp_7 release];
//    [ecmp_6 release];
//    [ecmp_4 release];
//    [ecmp_2 release];
//}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    SafeTimerVC *vc = [[SafeTimerVC alloc] init];
//    NSLog(@"initVC: %@",vc);
    [self.navigationController pushViewController:vc animated:YES];
    [vc release]; vc = nil;
}

@end
